home *** CD-ROM | disk | FTP | other *** search
/ Scene 96 / Scene 96 International Edition (Zyklop Software) (Disc 2) (1997).iso / misc / coding / midas060 / src / vgatext.asm < prev    next >
Encoding:
Assembly Source File  |  1997-01-16  |  11.5 KB  |  439 lines

  1. ;*      VGATEXT.ASM
  2. ;*
  3. ;* VGA text output routines for MIDAS Sound System
  4. ;*
  5. ;* $Id: vgatext.asm,v 1.3 1997/01/16 18:41:59 pekangas Exp $
  6. ;*
  7. ;* Copyright 1996,1997 Housemarque Inc.
  8. ;*
  9. ;* This file is part of the MIDAS Sound System, and may only be
  10. ;* used, modified and distributed under the terms of the MIDAS
  11. ;* Sound System license, LICENSE.TXT. By continuing to use,
  12. ;* modify or distribute this file you indicate that you have
  13. ;* read the license and understand and accept it fully.
  14. ;*
  15.  
  16.  
  17. IDEAL
  18. P386
  19.  
  20. INCLUDE "lang.inc"
  21. INCLUDE "vgatext.inc"
  22.  
  23.  
  24. DATASEG
  25.  
  26.  
  27. IFDEF __PASCAL__
  28. IFDEF __PROTMODE__
  29. EXTRN   SegB800 : word
  30. ENDIF
  31. ENDIF
  32.  
  33. D_int   scrWidth                        ; Screen width in _bytes_ (!!)
  34.  
  35.  
  36.  
  37. IDATASEG
  38.  
  39.  
  40. hextable    DB    "0123456789ABCDEF"
  41.  
  42.  
  43. CODESEG
  44.  
  45.  
  46. ;/***************************************************************************\
  47. ;*
  48. ;* Macro:       STARTADDR
  49. ;*
  50. ;* Description: Calculates the start address in display memory
  51. ;*
  52. ;* Input:       segreg          segment register for address
  53. ;*              indexreg        index register for address
  54. ;*              xc              starting x coordinate
  55. ;*              yc              starting y coordinate
  56. ;*
  57. ;* Returns:     points segreg:indexreg to correct display memory byte
  58. ;*
  59. ;* Destroys:    _ax
  60. ;*
  61. ;\***************************************************************************/
  62.  
  63. MACRO   STARTADDR       segreg, indexreg, xc, yc
  64.  
  65.         mov     _ax,yc
  66.         dec     _ax
  67.         mul     [scrWidth]
  68.         mov     indexreg,xc             ; point indexter to dest in display
  69.         dec     indexreg                ; memory (160*y + 2*x)
  70.         shl     indexreg,1
  71.         add     indexreg,_ax
  72.  
  73. IFDEF __REALMODE__
  74.         mov     ax,0B800h               ; point segreg to display memory
  75.         mov     segreg,ax
  76. ELSE
  77. IFDEF __16__
  78.         mov     segreg,[SegB800]
  79. ELSE
  80.         add     indexreg,0B8000h
  81. ENDIF
  82. ENDIF
  83.  
  84. ENDM
  85.  
  86.  
  87.  
  88.  
  89.  
  90. ;/***************************************************************************\
  91. ;*
  92. ;* Function:    void vgaSetWidth(int width);
  93. ;*
  94. ;* Description: Sets the screen width used by text output routines
  95. ;*
  96. ;* Input:       int width               screen width in characters
  97. ;*
  98. ;\***************************************************************************/
  99.  
  100. PROC    vgaSetWidth     _funct  width : _int
  101.  
  102.         mov     _ax,[width]
  103.         shl     _ax,1
  104.         mov     [scrWidth],_ax
  105.  
  106.         ret
  107. ENDP
  108.  
  109.  
  110.  
  111.  
  112. ;/***************************************************************************\
  113. ;*
  114. ;* Function:     void vgaWriteText(int x, int y, char *txt);
  115. ;*
  116. ;* Description:  Writes text on the screen
  117. ;*
  118. ;* Input:     int x             X coordinate of string (up-left
  119. ;*                     corner is (1,1))
  120. ;*         int y             Y coordinate
  121. ;*         char *txt         pointer to null-terminated text
  122. ;*                     string, which may contain also the
  123. ;*                     following special characters:
  124. ;*                         \xFF - next char is attribute
  125. ;*                         \x7F - next char is RLE count for
  126. ;*                         the character following it
  127. ;*
  128. ;\***************************************************************************/
  129.  
  130. PROC    vgaWriteText    _funct  x : _int, y : _int, txt : _ptr
  131. USES    _si,_di,_bx
  132.  
  133.         STARTADDR es, _di, [x], [y]
  134.  
  135.         PUSHSEGREG ds
  136.  
  137.         LOADPTR ds,_si,[txt]            ; point ds:si to string
  138.  
  139.     mov    ah,07h            ; default attribute is 07h - white
  140.                     ; on black
  141.  
  142. @@lp:   mov     al,[_si]                ; get byte from string
  143.         inc     _si
  144.         test    al,al                   ; zero? (string termination)
  145.     jz    @@done
  146.  
  147.     cmp    al,0FFh         ; is next byte attribute?
  148.     je    @@attr
  149.  
  150.     cmp    al,07Fh         ; is next byte RLE count?
  151.     je    @@rle
  152.  
  153.         mov     [_esdi],ax              ; normal character - write to screen
  154.         add     _di,2
  155.     jmp    @@lp            ; and get next character
  156.  
  157. @@attr:
  158.         mov     ah,[_si]                ; get next attribute
  159.         inc     _si
  160.     jmp    @@lp            ; get next character
  161.  
  162. @@rle:
  163.         xor     _cx,_cx
  164.         mov     cl,[_si]                ; get RLE count
  165.         mov     al,[_si+1]              ; get RLE byte
  166.         add     _si,2
  167.     rep    stosw            ; draw characters
  168.     jmp    @@lp            ; get next character
  169.  
  170. @@done:
  171.         POPSEGREG ds
  172.  
  173.     ret
  174. ENDP
  175.  
  176.  
  177.  
  178.  
  179. ;/***************************************************************************\
  180. ;*
  181. ;* Function:     void vgaWriteStr(int x, int y, char *str, char attr,
  182. ;*                   int txtlen);
  183. ;*
  184. ;* Description:  Writes a string on the screen
  185. ;*
  186. ;* Input:     int x             X coordinate of the string
  187. ;*         int y             Y coordinate
  188. ;*         char *str         pointer to a ASCIIZ string
  189. ;*         char attr         attribute for the string
  190. ;*         int txtlen         number of characters to be printed on
  191. ;*                     screen - padded with spaces
  192. ;*
  193. ;\***************************************************************************/
  194.  
  195. PROC    vgaWriteStr     _funct  x : _int, y : _int, str : _ptr, attr : _int,\
  196.                                 maxlen : _int
  197. USES    _si,_di,_bx
  198.  
  199.         STARTADDR es, _di, [x], [y]
  200.  
  201.         PUSHSEGREG ds
  202.  
  203.         LOADPTR ds,_si,[str]            ; point ds:si to string
  204.  
  205.         mov     ah,[byte attr]          ; attribute
  206.         mov     _cx,[maxlen]            ; maximum number of characters
  207.         test    _cx,_cx
  208.         jz      @@done
  209.  
  210. @@lp:    lodsb                ; get character
  211.         test    al,al                   ; zero? (end of string)
  212.     jz    @@send            ; if is, stop
  213.     stosw                ; write character and attribute
  214.     loop    @@lp            ; and get next character
  215.     jmp    @@done
  216.  
  217. @@send:
  218.         mov     al,' '                  ; string end - pad with spaces
  219.     rep    stosw
  220.  
  221. @@done:
  222.         POPSEGREG ds
  223.  
  224.     ret
  225. ENDP
  226.  
  227.  
  228.  
  229.  
  230. ;/***************************************************************************\
  231. ;*
  232. ;* Function:     void vgaWriteByte(int x, int y, uchar byte, char attr);
  233. ;*
  234. ;* Description:  Writes a hex byte on the screen
  235. ;*
  236. ;* Input:     int x             X coordinate
  237. ;*         int y             Y coordinate
  238. ;*         uchar byte         byte to be written
  239. ;*         char attr         attribute for the byte
  240. ;*
  241. ;\***************************************************************************/
  242.  
  243. PROC    vgaWriteByte    _funct  x : _int, y : _int, b : _int, attr : _int
  244. USES    _di,_bx
  245.  
  246.         STARTADDR es, _di, [x], [y]
  247.  
  248.         mov     ah,[byte attr]          ; attribute
  249.         mov     bl,[byte b]
  250.         shr     _bx,4                   ; upper nybble
  251.         and     _bx,0Fh
  252.         mov     al,[hextable+_bx]       ; upper nybble character
  253.         mov     [_esdi],ax              ; write upper nybble
  254.  
  255.         mov     bl,[byte b]
  256.     and    bx,0Fh            ; lower nybble
  257.         mov     al,[hextable+_bx]       ; lower nybble character
  258.         mov     [_esdi+2],ax            ; write lower nybble
  259.  
  260.     ret
  261. ENDP
  262.  
  263.  
  264.  
  265.  
  266. ;/***************************************************************************\
  267. ;*
  268. ;* Function:     void vgaFillRect(int x1, int y1, int x2, int y2, char attr);
  269. ;*
  270. ;* Description:  Draws a filled rectangle on the screen
  271. ;*
  272. ;* Input:        int x1                  X-coordinate of upper left corner
  273. ;*               int y1                  Y-coordinate of upper left corner
  274. ;*               int x2                  X-coordinate of lower left corner
  275. ;*               int y2                  Y-coordinate of lower left corner
  276. ;*               char attr               rectangle attribute
  277. ;*
  278. ;\***************************************************************************/
  279.  
  280. PROC    vgaFillRect     _funct  x1 : _int, y1 : _int, x2 : _int, y2 : _int, \
  281.                                 attr : _int
  282. USES    _si,_di,_bx
  283.  
  284.         cld
  285.  
  286.         STARTADDR es, _di, [x1], [y1]
  287.  
  288.         mov     _bx,[y2]
  289.         sub     _bx,[y1]                ; _bx = row counter (y2-y1+1)
  290.         inc     _bx
  291.  
  292.         mov     _dx,[x2]
  293.         sub     _dx,[x1]                ; _dx = number of columns (x2-x1+1)
  294.         inc     _dx
  295.  
  296.         mov     _ax,_dx
  297.         shl     _ax,1                   ; _si = number of bytes to skip
  298.         mov     _si,160                 ; at the end of each row
  299.         sub     _si,_ax                 ; (160 - 2*width)
  300.  
  301.         mov     ah,[byte attr]          ; ah = attribute
  302.         mov     al,' '
  303.  
  304. @@rowlp:
  305.         mov     _cx,_dx
  306.         rep     stosw                   ; draw one row's space+attr pairs
  307.         add     _di,_si                 ; point di to beginning of next row
  308.         dec     _bx
  309.         jnz     @@rowlp                 ; do next row
  310.  
  311.         ret
  312. ENDP
  313.  
  314.  
  315.  
  316.  
  317. ;/***************************************************************************\
  318. ;*
  319. ;* Function:     void vgaDrawChar(int x, int y, char ch, char attr);
  320. ;*
  321. ;* Description:  Draws a single character on the screen
  322. ;*
  323. ;* Input:        int x                   character X-coordinate
  324. ;*               int y                   character Y-coordinate
  325. ;*               char ch                 character
  326. ;*               char attr               character attribute
  327. ;*
  328. ;\***************************************************************************/
  329.  
  330. PROC    vgaDrawChar     _funct  x : _int, y : _int, cha : _int, attr : _int
  331. USES    _bx
  332.  
  333.         STARTADDR es, _bx, [x], [y]
  334.  
  335.         mov     ah,[byte attr]          ; ah = attribute
  336.         mov     al,[byte cha]           ; al = character
  337.         mov     [_esbx],ax              ; draw character & attribute
  338.  
  339.         ret
  340. ENDP
  341.  
  342.  
  343.  
  344.  
  345. ;/***************************************************************************\
  346. ;*
  347. ;* Function:     void vgaSetMode(int mode)
  348. ;*
  349. ;* Description:  Sets a VGA BIOS display mode
  350. ;*
  351. ;* Input:        int mode                BIOS mode number
  352. ;*
  353. ;\***************************************************************************/
  354.  
  355. PROC    vgaSetMode      _funct  mode : _int
  356. USES    _bx
  357.  
  358.         mov     al,[byte mode]
  359.         xor     ah,ah                   ; int 10h, function 0 - set display
  360.         int     10h                     ; mode
  361.  
  362.         ret
  363. ENDP
  364.  
  365.  
  366.  
  367.  
  368. ;/***************************************************************************\
  369. ;*
  370. ;* Function:     void vgaMoveCursor(int x, int y);
  371. ;*
  372. ;* Description:  Moves the text mode cursor to a new location
  373. ;*
  374. ;* Input:        int x                   cursor X-coordinate
  375. ;*               int y                   cursor Y-coordinate
  376. ;*
  377. ;\***************************************************************************/
  378.  
  379. PROC    vgaMoveCursor   _funct  x : _int, y : _int
  380. USES    _bx
  381.  
  382.         mov     ax,0200h                ; int 10h, function 2 - set cursor
  383.                                         ; location
  384.         xor     bx,bx                   ; bh = display page (0)
  385.         mov     dl,[byte x]             ; dl = column (0-based)
  386.         dec     dl
  387.         mov     dh,[byte y]             ; dh = row (0-based)
  388.         dec     dh
  389.         int     10h
  390.  
  391.         ret
  392. ENDP
  393.  
  394.  
  395.  
  396.  
  397. ;/***************************************************************************\
  398. ;*
  399. ;* Function:     void vgaDrawChars(int x, int y, char ch, char attr, int num);
  400. ;*
  401. ;* Description:  Draws many charactersr on the screen
  402. ;*
  403. ;* Input:        int x                   character X-coordinate
  404. ;*               int y                   character Y-coordinate
  405. ;*               char ch                 character
  406. ;*               char attr               character attribute
  407. ;*               int num                 number characters to draw
  408. ;*
  409. ;\***************************************************************************/
  410.  
  411. PROC    vgaDrawChars    _funct  x : _int, y : _int, cha : _int, attr : _int, \
  412.                                 num : _int
  413. USES    _di
  414.  
  415.         STARTADDR es, _di, [x], [y]
  416.  
  417.         mov     ah,[byte attr]          ; ah = attribute
  418.         mov     al,[byte cha]           ; al = character
  419.         mov     _cx,[num]               ; number of characters to draw
  420.         cld
  421.         rep     stosw                   ; draw characted-attribute pairs
  422.  
  423.         ret
  424. ENDP
  425.  
  426.  
  427.  
  428. ;* $Log: vgatext.asm,v $
  429. ;* Revision 1.3  1997/01/16 18:41:59  pekangas
  430. ;* Changed copyright messages to Housemarque
  431. ;*
  432. ;* Revision 1.2  1996/08/04 11:34:55  pekangas
  433. ;* All functions now preserve _bx
  434. ;*
  435. ;* Revision 1.1  1996/05/22 20:49:33  pekangas
  436. ;* Initial revision
  437. ;*
  438.  
  439. END